<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/limh/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/limh/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/limh/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/limh/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/limh/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/limh/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/limh/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="教程,">










<meta name="description" content="在学习高级语言程序设计时，我们知道了程序的三大主要结构：顺序结构、分支结构和循环结构。在汇编语言的源程序也同样有此三大结构，所不同的是它们的表现形式不同。用高级语言编写程序时，由于不使用“转移语句”而使这三种结构清晰明了。 但在汇编语言的源程序中，很难不使用“转移语句”(除非是一些只有简单功能的程序)，有时甚至会有各种各样的“转移语句”。由于存在这些转移语句，就使得：汇编语言源程序的基本结构显得不">
<meta name="keywords" content="教程">
<meta property="og:type" content="article">
<meta property="og:title" content="6.2 程序的基本结构">
<meta property="og:url" content="https://tdnr.gitee.io/limh/2015/04/01/asm24/index.html">
<meta property="og:site_name" content="土逗牛肉">
<meta property="og:description" content="在学习高级语言程序设计时，我们知道了程序的三大主要结构：顺序结构、分支结构和循环结构。在汇编语言的源程序也同样有此三大结构，所不同的是它们的表现形式不同。用高级语言编写程序时，由于不使用“转移语句”而使这三种结构清晰明了。 但在汇编语言的源程序中，很难不使用“转移语句”(除非是一些只有简单功能的程序)，有时甚至会有各种各样的“转移语句”。由于存在这些转移语句，就使得：汇编语言源程序的基本结构显得不">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://www.iteedu.com/plang/asm/asmhbyychxshj/images/clip_image003_0012.gif">
<meta property="og:image" content="http://www.iteedu.com/plang/asm/asmhbyychxshj/images/clip_image004_0003.gif">
<meta property="og:image" content="http://www.iteedu.com/plang/asm/asmhbyychxshj/images/clip_image001_0084.gif">
<meta property="og:image" content="http://www.iteedu.com/plang/asm/asmhbyychxshj/images/clip_image002_0025.gif">
<meta property="og:updated_time" content="2019-01-21T13:59:48.417Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="6.2 程序的基本结构">
<meta name="twitter:description" content="在学习高级语言程序设计时，我们知道了程序的三大主要结构：顺序结构、分支结构和循环结构。在汇编语言的源程序也同样有此三大结构，所不同的是它们的表现形式不同。用高级语言编写程序时，由于不使用“转移语句”而使这三种结构清晰明了。 但在汇编语言的源程序中，很难不使用“转移语句”(除非是一些只有简单功能的程序)，有时甚至会有各种各样的“转移语句”。由于存在这些转移语句，就使得：汇编语言源程序的基本结构显得不">
<meta name="twitter:image" content="http://www.iteedu.com/plang/asm/asmhbyychxshj/images/clip_image003_0012.gif">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/limh/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://tdnr.gitee.io/limh/2015/04/01/asm24/">





  <title>6.2 程序的基本结构 | 土逗牛肉</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans ">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/limh/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">土逗牛肉</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/limh/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/limh/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/limh/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/limh/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/limh/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://tdnr.gitee.io/limh/limh/2015/04/01/asm24/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="土逗牛肉">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/limh/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="土逗牛肉">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">6.2 程序的基本结构</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2015-04-01T20:35:49+08:00">
                2015-04-01
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/limh/categories/汇编教程/" itemprop="url" rel="index">
                    <span itemprop="name">汇编教程</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>在学习高级语言程序设计时，我们知道了程序的三大主要结构：顺序结构、分支结构和循环结构。在汇编语言的源程序也同样有此三大结构，所不同的是它们的表现形式不同。用高级语言编写程序时，由于不使用“转移语句”而使这三种结构清晰明了。</p>
<p>但在汇编语言的源程序中，很难不使用“转移语句”(除非是一些只有简单功能的程序)，有时甚至会有各种各样的“转移语句”。由于存在这些转移语句，就使得：汇编语言源程序的基本结构显得不太明确。如果源程序的编写者思维混乱，编写出来的源程序在结构上就会显得杂乱无章，反之，如果编写者条理清晰，安排的操作井然有序，那么，编写出来的程序在结构上就会一目了然。</p>
<p>总之，不论是高级语言的源程序，还是汇编语言的源程序，其程序的三大基本结构也还是万变不离其宗的。</p>
<hr>
<h2 id="6-2-1-顺序结构"><a href="#6-2-1-顺序结构" class="headerlink" title="6.2.1 顺序结构"></a>6.2.1 顺序结构</h2><p>顺序结构是最简单的程序结构，程序的执行顺序就是指令的编写顺序，所以，安排指令的先后次序就显得至关重要。另外，在编程序时，还要妥善保存已得到的处理结果，为后面的进一步处理直接提供前面的处理结果，从而避免不必要的重复操作。</p>
<p><strong>例6.3 编写程序段，完成下面公式的计算(其中：变量X和Y是32位有符号数，变量A，B和Z是16位有符号数)。</strong></p>
<p>A←(X-Y+24)/Z的商，B←(X-Y+24)/Z的余数</p>
<p>解：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">DATA1  SEGMENT</span><br><span class="line"></span><br><span class="line">       X DD　?</span><br><span class="line"></span><br><span class="line">       Y DD　?</span><br><span class="line"></span><br><span class="line">       Z DW　?</span><br><span class="line"></span><br><span class="line">       A DW　?</span><br><span class="line"></span><br><span class="line">       B DW　?</span><br><span class="line"></span><br><span class="line">       …</span><br><span class="line"></span><br><span class="line">DATA1  ENDS</span><br><span class="line"></span><br><span class="line">CODE1  SEGMENT</span><br><span class="line"></span><br><span class="line">       …</span><br><span class="line"></span><br><span class="line">       MOV       AX, X</span><br><span class="line"></span><br><span class="line">       MOV       DX, X+2     ;用(DX:AX)来保存32位变量X的数值</span><br><span class="line"></span><br><span class="line">       SUB       AX,Y</span><br><span class="line"></span><br><span class="line">       SBB       DX, Y+2     ;(DX:AX)-(Y+2:Y)</span><br><span class="line"></span><br><span class="line">       ADD       AX, 24D</span><br><span class="line"></span><br><span class="line">       ADC       DX, 0       ;(DX:AX)+24</span><br><span class="line"></span><br><span class="line">       IDIV      Z</span><br><span class="line"></span><br><span class="line">       MOV       A, AX</span><br><span class="line"></span><br><span class="line">       MOV       B, DX</span><br><span class="line"></span><br><span class="line">       …</span><br><span class="line"></span><br><span class="line">CODE1  ENDS</span><br></pre></td></tr></table></figure>
<p>在编程序时，常常需要交换二变量之值。假设需要交换值的变量名为：var1和var2，临时增加的变量名为temp。常用的算法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">temp  =         var1</span><br><span class="line"></span><br><span class="line">var1  =         var2</span><br><span class="line"></span><br><span class="line">var2  =         temp</span><br></pre></td></tr></table></figure>
<p><strong>例6.4 假设有二个字变量word1和word2，编写程序段实现交换其值的功能。</strong></p>
<p>解：</p>
<p>方法1：用汇编语言指令简单“直译”上面的 交换数据方法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">DATA1 SEGMENT</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">word1 DW　?</span><br><span class="line"></span><br><span class="line">word2 DW　?</span><br><span class="line"></span><br><span class="line">temp? DW　?</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">DATA1 ENDS</span><br><span class="line"></span><br><span class="line">CODE1 SEGMENT</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">MOV AX, word1</span><br><span class="line"></span><br><span class="line">MOV temp, AX ;上二语句实现语句“temp=word1”</span><br><span class="line"></span><br><span class="line">MOV AX, word2</span><br><span class="line"></span><br><span class="line">MOV word1, AX? ;上二语句实现语句“word1=word2”</span><br><span class="line"></span><br><span class="line">MOV AX, temp</span><br><span class="line"></span><br><span class="line">MOV word2, AX? ;上二语句实现语句“word2=temp”</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">CODE1 ENDS</span><br></pre></td></tr></table></figure>
<p>这种方法虽然也能完成功能，但显然其不能充分利用汇编语言的特点，程序效率很低。</p>
<p>方法2：用汇编语言指令的特点来直接编译</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">DATA1 SEGMENT</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">word1 DW　?</span><br><span class="line"></span><br><span class="line">word2 DW　?</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">DATA1 ENDS</span><br><span class="line"></span><br><span class="line">CODE1 SEGMENT</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">MOV AX, word1</span><br><span class="line"></span><br><span class="line">XCHG AX, word2</span><br><span class="line"></span><br><span class="line">MOV word1, AX ;能XCHG word1, word2来代替这三条指令吗？</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">CODE1 ENDS</span><br></pre></td></tr></table></figure>
<p>该方法充分利用了汇编语言的特点，不仅省去了中间变量temp的定义，而且程序的效率也提高了。</p>
<h2 id="6-2-2-分支结构"><a href="#6-2-2-分支结构" class="headerlink" title="6.2.2 分支结构"></a>6.2.2 分支结构</h2><p>分支结构是一种非常重要的程序结构，也是实现程序功能选择所必要的程序结构。由于汇编语言需要书写转移指令来实现分支结构，而转移指令肯定会破坏程序的结构，所以，编写清晰的分支结构是掌握该结构的重点，也是用汇编语言编程的基本功。</p>
<p>在程序中，当需要进行逻辑分支时，可用每次分二支的方法来达到程序最终分多支的要求，也可是用地址表的方法来达到分多支的目的。</p>
<h3 id="一、显示转移指令实现的分支结构"><a href="#一、显示转移指令实现的分支结构" class="headerlink" title="一、显示转移指令实现的分支结构"></a>一、显示转移指令实现的分支结构</h3><p>在高级语句中，分支结构一般用IF语句来实现，在汇编语言中，课用无条件转移指令或条件转移指令实现的分支结构。如图6.2给出了二种常用的分支结构。</p>
<p>在编写分支程序时，要尽可能避免编写“头重脚轻”的结构，即：当前分支条件成立时，将执行一系列指令，而条件不成立时，所执行的指令很少。这样就使后一个分支离分支点较远，有时甚至会遗忘编写后一分支程序。这种分支方式不仅不利于程序的阅读，而且也不便将来的维护。</p>
<p>所以，在编写分支结构时，一般先处理简单的分支，再处理较复杂的分支。对多分支的情况，也可遵循“由易到难”的原则。因为简单的分支只需要较少的指令就能处理完，一旦处理完这种情况后，在后面的编程过程中就可集中考虑如何处理复杂的分支。</p>
<p><img src="http://www.iteedu.com/plang/asm/asmhbyychxshj/images/clip_image003_0012.gif" alt></p>
<center>(a) if … endif结构</center>

<p><img src="http://www.iteedu.com/plang/asm/asmhbyychxshj/images/clip_image004_0003.gif" alt="(b) if…else…endif结构"></p>
<center>(b) if…else…endif结构</center>

<center><strong>图6.2 分支结构的二种结构</strong></center>

<p><strong>例6.5 已知字节变量CHAR1，编写一程序段，把它由小写字母变成大写字母。</strong></p>
<p>解：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">DATA1 SEGMENT</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">CHAR1 DB　?</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">DATA1 ENDS</span><br><span class="line"></span><br><span class="line">CODE1 SEGMENT</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">MOV AL, CHAR1</span><br><span class="line"></span><br><span class="line">CMP AL, ‘a’</span><br><span class="line"></span><br><span class="line">JB next</span><br><span class="line"></span><br><span class="line">CMP AL, ‘z’</span><br><span class="line"></span><br><span class="line">JA next</span><br><span class="line"></span><br><span class="line">SUB CHAR1, 20H ;指令AND CHAR1, 0DFH也可以</span><br><span class="line"></span><br><span class="line">next: …</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">CODE1 ENDS</span><br></pre></td></tr></table></figure>
<p><strong>例6.6 编写一程序段，计算下列函数值。其中：变量X和Y是有符号字变量。</strong></p>
<p>解：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">DATA1 SEGMENT</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">X DW　?</span><br><span class="line"></span><br><span class="line">Y DW　?</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">DATA1 ENDS</span><br><span class="line"></span><br><span class="line">CODE1 SEGMENT</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">MOV AX, X</span><br><span class="line"></span><br><span class="line">CMP AX, 0</span><br><span class="line"></span><br><span class="line">JGE case23</span><br><span class="line"></span><br><span class="line">ADD AX, 10 ;第一种情况的计算结果</span><br><span class="line"></span><br><span class="line">JMP result</span><br><span class="line"></span><br><span class="line">case23: CMP AX, 10D</span><br><span class="line"></span><br><span class="line">JG case3</span><br><span class="line"></span><br><span class="line">MOV BX, 30D</span><br><span class="line"></span><br><span class="line">IMUL BX ;第二种情况的计算结果</span><br><span class="line"></span><br><span class="line">JMP result</span><br><span class="line"></span><br><span class="line">case3: SUB AX, 9 ;第三种情况的计算结果</span><br><span class="line"></span><br><span class="line">result: MOV Y, AX ;把计算结果保存到变量Y中</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">CODE1 ENDS</span><br></pre></td></tr></table></figure>
<p>例6.7 把下列C语言的语句改写成等价的汇编语言程序段(不考虑运算过程中的溢出)。</p>
<p>If (a+b &gt; 0 &amp;&amp; c%2 == 0) a = 62;</p>
<p>else a = 21;</p>
<p>其中：变量a，b和c都是有符号的整型(int)变量。</p>
<p>解：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">DATA1 SEGMENT</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">A? DW　?</span><br><span class="line"></span><br><span class="line">B DW　?</span><br><span class="line"></span><br><span class="line">C? DW　?</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">DATA1 ENDS</span><br><span class="line"></span><br><span class="line">CODE1 SEGMENT</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">MOV AX, A</span><br><span class="line"></span><br><span class="line">ADD AX, B</span><br><span class="line"></span><br><span class="line">JLE _ELSE ;ADD指令会改变算术标志位 </span><br><span class="line"></span><br><span class="line">TEST C, 1 ;C%2==0，也就是：看C的最低位是否为0</span><br><span class="line"></span><br><span class="line">JNZ _ELSE</span><br><span class="line"></span><br><span class="line">MOV A, 62D</span><br><span class="line"></span><br><span class="line">JMP NEXT</span><br><span class="line"></span><br><span class="line">_ELSE:?MOV A, 21D</span><br><span class="line"></span><br><span class="line">NEXT: …</span><br><span class="line"></span><br><span class="line">CODE1 ENDS</span><br></pre></td></tr></table></figure>
<p>例6.8 用地址转移表实现下列C语言的switch语句，其中：变量A和B是有符号的整型(int)变量。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">switch (a%8)</span><br><span class="line"></span><br><span class="line">&#123;case 0: b = 32;</span><br><span class="line"></span><br><span class="line">break;</span><br><span class="line"></span><br><span class="line">case 1:</span><br><span class="line"></span><br><span class="line">case 2: b = a + 43;</span><br><span class="line"></span><br><span class="line">break;</span><br><span class="line"></span><br><span class="line">case 3: b = 2*a;</span><br><span class="line"></span><br><span class="line">break;</span><br><span class="line"></span><br><span class="line">case 4: b--;</span><br><span class="line"></span><br><span class="line">break;</span><br><span class="line"></span><br><span class="line">case 5:</span><br><span class="line"></span><br><span class="line">case 6:</span><br><span class="line"></span><br><span class="line">case 7: printf(“Function 5_6_7”);</span><br><span class="line"></span><br><span class="line">break;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>解：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line">DATA1 SEGMENT</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">A DW　?</span><br><span class="line"></span><br><span class="line">B DW　?</span><br><span class="line"></span><br><span class="line">Table DW　case0. case12, case12, case3</span><br><span class="line"></span><br><span class="line">DW　case4, case567, case567, case567</span><br><span class="line"></span><br><span class="line">MSG DB　&apos;Function 5_6_7$&apos;</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">DATA1 ENDS</span><br><span class="line"></span><br><span class="line">CODE1 SEGMENT</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">MOV AX, A</span><br><span class="line"></span><br><span class="line">MOV BX, AX</span><br><span class="line"></span><br><span class="line">AND BX, 7 ;得到BX的低三位，实现a%8的计算</span><br><span class="line"></span><br><span class="line">SHL BX, 1 ;由于地址表是字类型，其下标要乘2</span><br><span class="line"></span><br><span class="line">JMP Table[BX]? ;利用地址表实现多路转移</span><br><span class="line"></span><br><span class="line">case0: MOV B, 32D</span><br><span class="line"></span><br><span class="line">JMP next</span><br><span class="line"></span><br><span class="line">case12: ADD AX, 43D</span><br><span class="line"></span><br><span class="line">MOV B, AX</span><br><span class="line"></span><br><span class="line">JMP next</span><br><span class="line"></span><br><span class="line">case3: SHL AX, 1</span><br><span class="line"></span><br><span class="line">MOV B, AX</span><br><span class="line"></span><br><span class="line">JMP next</span><br><span class="line"></span><br><span class="line">case4: DEC? B</span><br><span class="line"></span><br><span class="line">JMP next</span><br><span class="line"></span><br><span class="line">case567: LEA?DX, MSG</span><br><span class="line"></span><br><span class="line">MOV AH, 9</span><br><span class="line"></span><br><span class="line">INT 21H</span><br><span class="line"></span><br><span class="line">JMP next</span><br><span class="line"></span><br><span class="line">next: …</span><br><span class="line"></span><br><span class="line">CODE1 ENDS</span><br></pre></td></tr></table></figure>
<p>用地址表实现多路转移的关键在于：转移入口的地址表和转移情况可整数化。如果这二个要求有一个不满足，或很难构造，则无法使用该方法。</p>
<h3 id="二、用伪指令实现的分支结构"><a href="#二、用伪指令实现的分支结构" class="headerlink" title="二、用伪指令实现的分支结构"></a>二、用伪指令实现的分支结构</h3><p>为了改善汇编语言源程序的结构，减少显式转移语句所带来混乱，在宏汇编MASM 6.11系统中，增加了表达分支结构的伪指令。该伪指令的书写格式与高级语言的书写方式相类似，汇编程序在汇编时会自动增加转移指令和相应的标号。理解并掌握该知识，对将来学习《编译原理》课程也有一定的帮助。</p>
<p>分支伪指令的具体格式如下：</p>
<p>格式1：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">.IF condition　;以英文“句号”开头 </span><br><span class="line"></span><br><span class="line">指令序列　;条件&quot;condition&quot;成立时所执行的指令序列 </span><br><span class="line">.ENDIF</span><br></pre></td></tr></table></figure>
<p>格式2：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">.IF condition</span><br><span class="line"></span><br><span class="line">指令序列1</span><br><span class="line"></span><br><span class="line">.ELSE</span><br><span class="line"></span><br><span class="line">指令序列2　;条件&quot;condition&quot;不成立时所执行的指令序列 </span><br><span class="line"></span><br><span class="line">.ENDIF</span><br></pre></td></tr></table></figure>
<p>格式3：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">.IF condition1</span><br><span class="line"></span><br><span class="line">指令序列1</span><br><span class="line"></span><br><span class="line">.ELSEIF condition2</span><br><span class="line"></span><br><span class="line">指令序列2　;条件&quot;condition2&quot;成立时所执行的指令序列 </span><br><span class="line"></span><br><span class="line">.ENDIF</span><br></pre></td></tr></table></figure>
<p>其中：条件表达式“condition”的书写方式与C语言中条件表达式的书写方式相似，也可用括号来组成复杂的条件表达式。</p>
<p>条件表达式中可用的操作符有：==(等于)、!=(不等)、&gt;(大于)、&gt;=(大于等于)、&lt;(小于)、&lt;=(小于等于)、&amp;(位操作与)、!(逻辑非)、&amp;&amp;(逻辑与)、||(逻辑或)等。</p>
<p>若在条件表达式中检测标志位的信息，则可以使用的符号名有：CARRY(相当于CF==1)、OVERFLOW(OF==1)、PARITY(PF==1)、SIGN(SF==1)、ZERO (ZF==1)等。例如：</p>
<p>.IF　CARRY? &amp;&amp; AX != BX　;检测CF==1且AX!=BX是否成立 </p>
<p>;汇编语言指令序列 </p>
<p>.ENDIF<br>在指令序列中，还可再含有其它的.IF伪指令，即：允许嵌套。伪指令.ELSEIF引导出另一个二叉分支，但它不能作伪指令块的第一个伪指令。</p>
<p>汇编程序在对“条件表达式”进行代码转换时将进行代码优化处理，以便尽可能生成最好的指令代码。如：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">.IF　ax == 0</span><br></pre></td></tr></table></figure>
<p>汇编程序会把它转换为指令“OR　ax, ax”，而不是“CMP　ax, 0”，因为前者比后者更好，而不是简单直接地转换为后者。</p>
<p>如果用伪指令来书写分支结构，那么，例6.5的代码段部分就可写成如下程序段：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">…</span><br><span class="line"></span><br><span class="line">MOV AL, CHAR1</span><br><span class="line"></span><br><span class="line">.IF　AL&gt;=&apos;a&apos; &amp;&amp; AL&lt;=&apos;z&apos; ;语句象C语言语句吗？</span><br><span class="line"></span><br><span class="line">SUB　CHAR1, 20H</span><br><span class="line"></span><br><span class="line">.ENDIF</span><br><span class="line"></span><br><span class="line">…</span><br></pre></td></tr></table></figure>
<p>也可把例6.6的代码段部分就可写成如下程序段：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">…</span><br><span class="line"></span><br><span class="line">MOV AX, X</span><br><span class="line"></span><br><span class="line">.IF?AX &lt; 0</span><br><span class="line"></span><br><span class="line">ADD　AX, 10? ;计算第一种情况的结果</span><br><span class="line"></span><br><span class="line">.ELSEIF　AX &lt;= 10</span><br><span class="line"></span><br><span class="line">MOV　BX, 30D</span><br><span class="line"></span><br><span class="line">IMUL　BX ;计算第二种情况的结果</span><br><span class="line"></span><br><span class="line">.ELSE</span><br><span class="line"></span><br><span class="line">SUB　AX, 9 ;计算第三种情况的结果</span><br><span class="line"></span><br><span class="line">.ENDIF</span><br><span class="line"></span><br><span class="line">MOV　Y, AX</span><br><span class="line"></span><br><span class="line">… ;把计算结果保存到变量Y中</span><br></pre></td></tr></table></figure>
<p>例6.9 根据当前计算机的时间和日期，显示上午(AM)或下午(PM)，以及所在的季节。</p>
<p>解：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"> DATA1 SEGMENT </span><br><span class="line"> MSG DB　&quot;Time: &quot; </span><br><span class="line">AmPm DB　&quot;AM&quot;, 13, 10  </span><br><span class="line"> DB　&quot;Season: $&quot; </span><br><span class="line">winter DB　&quot;Winter$&quot; </span><br><span class="line">spring DB　&quot;Spring$&quot; </span><br><span class="line">summer DB　&quot;Summer$&quot; </span><br><span class="line">autumn DB　&quot;Autumn$&quot;  </span><br><span class="line">DATA1 ENDS </span><br><span class="line">CODE1 SEGMENT </span><br><span class="line"> … </span><br><span class="line">MOV　AH, 2CH ;取当前系统时间 </span><br><span class="line">INT　21H </span><br><span class="line">.IF CH &gt;= 12  ;下午时间 </span><br><span class="line">　　MOV AmPm, &apos;P&apos;  ;为显示PM作安排 </span><br><span class="line">.ENDIF </span><br><span class="line">MOV　DX, OFFSET MSG </span><br><span class="line">MOV　AH, 09H </span><br><span class="line">INT　21H ;显示字符串MSG，直到&apos;$&apos;结束 </span><br><span class="line">MOV　AH, 2AH </span><br><span class="line">INT　21H ;取当前系统日期 </span><br><span class="line">.IF (DH == 12) || (DH &lt; 3)  ;判断是否为12月，1月和2月 </span><br><span class="line">　　MOV　DX, OFFSET winter </span><br><span class="line">.ELSEIF (DH &gt;= 3) &amp;&amp; (DH &lt; 6) ;判断是否为3、4和5月 </span><br><span class="line">　　MOV　DX, OFFSET spring </span><br><span class="line">.ELSEIF (DH &gt;= 6) &amp;&amp; (DH &lt; 9) ;判断是否为6、7和8月 </span><br><span class="line">　　MOV　DX, OFFSET summer </span><br><span class="line">.ELSE ;9、10和11月 </span><br><span class="line">　　MOV DX, OFFSET autumn </span><br><span class="line">.ENDIF </span><br><span class="line">MOV AH, 09H ;显示季度名称 </span><br><span class="line">INT 21H </span><br><span class="line">… </span><br><span class="line">END</span><br></pre></td></tr></table></figure>
<h2 id="6-2-3-循环结构"><a href="#6-2-3-循环结构" class="headerlink" title="6.2.3 循环结构"></a>6.2.3 循环结构</h2><p>循环结构是一个重要的程序结构，它具有重复执行某段程序的功能。通常，循环结构包括以下四个组成部分：</p>
<ol>
<li>循环初始化部分——初始化循环控制变量、循环体所用到变量；</li>
<li>循环体部分——循环结构的主体；</li>
<li>循环调整部分——循环控制变量的修改、或循环终止条件的检查；</li>
<li>循环控制部分——程序执行的控制转移。</li>
</ol>
<p>以上四部分可以在程序中用各种不同的形式体现出来，有时也并非清析地表达出来。常用的循环结构如图6.3所示。</p>
<p><img src="http://www.iteedu.com/plang/asm/asmhbyychxshj/images/clip_image001_0084.gif" alt="(a)、Do—While结构"></p>
<center>(a)、Do—While结构</center>

<p><img src="http://www.iteedu.com/plang/asm/asmhbyychxshj/images/clip_image002_0025.gif" alt="(b)、While结构"></p>
<center>(b)、While结构</center>

<center><strong>图6.3 常用的循环结构示意图</strong></center>

<h3 id="一、用循环指令构成循环结构"><a href="#一、用循环指令构成循环结构" class="headerlink" title="一、用循环指令构成循环结构"></a>一、用循环指令构成循环结构</h3><p>在编写循环结构的程序片段时，我们可以多种方法来循环结构。如：循环次数是已知的，可用LOOP指令来构造循环；当循环次数是未知或不定的，则可用条件转移或无条件转移来构成循环结构。</p>
<p><strong>例6.10 分类统计字数组data中正数、负数和零的个数，并分别存入内存字变量Positive、Negative和Zero中，数组元素个数保存在其第一个字中。</strong></p>
<p>解：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">       DATA1  SEGMENT</span><br><span class="line">data DW　10 </span><br><span class="line">DW　2130, -43, 31, -321, -1234, 345, 0, 3213, 0, 5477 </span><br><span class="line">Positive DW　0 </span><br><span class="line">Negative DW　0 </span><br><span class="line">Zero DW　0 </span><br><span class="line">       DATA1  ENDS</span><br><span class="line">       CODE1  SEGMENT</span><br><span class="line">ASSUME　CS:CODE1, DS:DATA1 </span><br><span class="line">      START:  MOV       AX, DATA1</span><br><span class="line">              MOV       DS, AX</span><br><span class="line">              XOR       AX, AX      ;用AX来对正数计数</span><br><span class="line">              XOR       BX, BX      ;用BX来对负数计数</span><br><span class="line">              XOR       DX, DX      ;用DX来对零计数</span><br><span class="line">              MOV       CX, data    ;用CX来进行循环计数</span><br><span class="line">              JCXZ      save        ;考虑数组的元素个数为0的情况</span><br><span class="line">              LEA       SI, data+2  ;用指针SI来访问整个数组</span><br><span class="line">      again:  CMP       word ptr [SI], 0</span><br><span class="line">              JL        lower</span><br><span class="line">              JE        equal</span><br><span class="line">              INC       AX</span><br><span class="line">              JMP       loop1</span><br><span class="line">      lower:  INC       BX</span><br><span class="line">              JMP       loop1</span><br><span class="line">      equal:  INC       DX</span><br><span class="line">      loop1:  ADD       SI, 2</span><br><span class="line">              LOOP      again</span><br><span class="line">       save:  MOV       Positive, AX            ;把各类的统计数保存到内存单元中</span><br><span class="line">              MOV       Negative, BX</span><br><span class="line">              MOV       Zero, DX</span><br><span class="line">              MOV       AX, 4C00H</span><br><span class="line">              INT       21H</span><br><span class="line">       CODE1  ENDS</span><br><span class="line">              END</span><br></pre></td></tr></table></figure>
<p><strong>例6.11 计算数组score的平均整数，并存入内存字变量Average中，数组以-1为结束标志。</strong></p>
<p>解：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line">       DATA1  SEGMENT</span><br><span class="line"></span><br><span class="line">data DW　90, 95, 54, 65, 36, 78, 66, 0, 99, 50, -1</span><br><span class="line"></span><br><span class="line">Average DW　0</span><br><span class="line"></span><br><span class="line">       DATA1  ENDS</span><br><span class="line"></span><br><span class="line">       CODE1  SEGMENT</span><br><span class="line"></span><br><span class="line">ASSUME　CS:CODE1, DS:DATA1</span><br><span class="line"></span><br><span class="line">      START:  MOV       AX, DATA1</span><br><span class="line"></span><br><span class="line">              MOV       DS, AX</span><br><span class="line"></span><br><span class="line">              XOR       AX, AX</span><br><span class="line"></span><br><span class="line">              XOR       DX, DX      ;用(DX，AX)来保存数组元素之和</span><br><span class="line"></span><br><span class="line">              XOR       CX, CX      ;用CX来保存数组元素个数</span><br><span class="line"></span><br><span class="line">              LEA       SI, data    ;用指针SI来访问整个数组</span><br><span class="line"></span><br><span class="line">      again:  MOV       BX, word ptr [SI]</span><br><span class="line"></span><br><span class="line">              CMP       BX, 0</span><br><span class="line"></span><br><span class="line">              JL        over</span><br><span class="line"></span><br><span class="line">              ADD       AX, BX</span><br><span class="line"></span><br><span class="line">              ADC       DX, 0       ;把当前数组元素之值加到(DX，AX)中</span><br><span class="line"></span><br><span class="line">              INC       CX          ;数组元素个数加1</span><br><span class="line"></span><br><span class="line">              ADD       SI, 2</span><br><span class="line"></span><br><span class="line">              JMP       again</span><br><span class="line"></span><br><span class="line">       over:  JCXZ      exit        ;防止零作除数，即数组是空数组</span><br><span class="line"></span><br><span class="line">              DIV       CX</span><br><span class="line"></span><br><span class="line">              MOV       Average, AX</span><br><span class="line"></span><br><span class="line">       exit:  MOV       AX, 4C00H</span><br><span class="line"></span><br><span class="line">              INT       21H</span><br><span class="line"></span><br><span class="line">       CODE1  ENDS</span><br><span class="line"></span><br><span class="line">              END       START</span><br></pre></td></tr></table></figure>
<h3 id="二、用伪指令实现的循环结构"><a href="#二、用伪指令实现的循环结构" class="headerlink" title="二、用伪指令实现的循环结构"></a>二、用伪指令实现的循环结构</h3><p>在宏汇编MASM 6.11系统中，还增加了表达循环结构的伪指令，以便更清晰地表达WHILE循环、REPEAT-UNTIL循环。另外，还增加两个辅助循环的伪指令。这些伪指令的书写格式和含义与高级语言中相应语句的书写格式和含义相一致，所以，这些伪指令是很容易掌握的，也是非常有用的。</p>
<p>循环伪指令的格式和含义如下：</p>
<h4 id="1、WHILE型循环伪指令"><a href="#1、WHILE型循环伪指令" class="headerlink" title="1、WHILE型循环伪指令"></a>1、WHILE型循环伪指令</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"> .WHILE  condition</span><br><span class="line">循环体的指令序列　　　　;条件&quot;condition”成立时所执行的指令序列 </span><br><span class="line"> .ENDW</span><br></pre></td></tr></table></figure>
<p>其中：.ENDW与前面的.WHILE相匹配，它标志着其循环体到此结束。</p>
<p>如果条件表达式“condition”在循环开始时，就为“假”(false)，那么，该循环体一次也不会被执行。</p>
<h4 id="2、REPEAT型循环伪指令"><a href="#2、REPEAT型循环伪指令" class="headerlink" title="2、REPEAT型循环伪指令"></a>2、REPEAT型循环伪指令</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">.REPEAT</span><br><span class="line"> 循环体的指令序列</span><br><span class="line"> .UNTIL condition  </span><br><span class="line"> .REPEAT</span><br><span class="line"> 循环体的指令序列</span><br><span class="line"> .UNTILCXZ [condition]</span><br></pre></td></tr></table></figure>
<p>REPEAT型循环在执行完循环体后，才判定逻辑表达式condition的值。若该表达式的值为真，则终止该循环，并将执行伪指令.UNTIL[CXZ]后面的指令，否则，将向上跳转到伪指令.REPEAT之后的指令，为继续执行其循环体作准备。</p>
<p>如果.UNTILCXZ后面没有写逻辑表达式，那么，由.REPEAT－.UNTILCXZ所构成的循环与用LOOP指令所过程的循环是一致的，它们都是以“CX=0”为循环终止条件。</p>
<p>如果.UNTILCXZ后面书写了逻辑表达式，那么，该逻辑表达式的形式只能是：“EXP1==EXP2”或“EXP1!=EXP2”。所以，这时由“.REPEAT－.UNTILCXZ condition”所构成的循环就与用LOOPNE/LOOPE指令所过程的循环是一致的，它们都是以“condition || CX=0”为循环终止条件。</p>
<p>和高级语言的REPEAT型的循环一样，.REPEAT－.UNTIL[CXZ]的循环体也会至少被执行一次。</p>
<p>.WHILE－.ENDW和.REPEAT－.UNTIL[CXZ]的循环体内还可再含有循环伪指令，这样就构成了循环结构的嵌套。</p>
<p>汇编程序在生产指令代码时会进行代码优化，以便尽可能得到最优化的指令序列。</p>
<h4 id="3、辅助循环伪指令"><a href="#3、辅助循环伪指令" class="headerlink" title="3、辅助循环伪指令"></a>3、辅助循环伪指令</h4><h5 id="1-、终止循环伪指令"><a href="#1-、终止循环伪指令" class="headerlink" title="(1)、终止循环伪指令"></a>(1)、终止循环伪指令</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">.BREAK </span><br><span class="line">.BREAK   .IF condition</span><br></pre></td></tr></table></figure>
<p>该伪指令用来终止包含它的最内层循环。前者是无条件终止循环，后者是仅当逻辑表达式condition为真时，才终止循环。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">.WHILE?1</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">.BREAK .IF condition</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">ENDW .REPEAT</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">.BREAK .IF condition</span><br><span class="line"></span><br><span class="line">…</span><br><span class="line"></span><br><span class="line">.UNTIL　0</span><br></pre></td></tr></table></figure>
<p>对于以上二个循环，如果没有指令来终止循环的话，它们都将进入死循环状态，但如果在该层循环体内，存在伪指令“.BREAK .IF condition”的话，那么，当逻辑表达式condition为真时，该循环就会被终止了。</p>
<h5 id="2-、循环继续伪指令"><a href="#2-、循环继续伪指令" class="headerlink" title="(2)、循环继续伪指令"></a>(2)、循环继续伪指令</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">.CONTINUE </span><br><span class="line"> .CONTINUE　.IF condition</span><br></pre></td></tr></table></figure>
<p>该伪指令用于直接跳转到包含它的最内层循环的计算循环条件表达式的代码处。前者是无条件转移到计算循环条件表达式的代码处，后者是仅当条件表达式condition为真时，才进行这样的跳转。</p>
<p>辅助循环伪指令.BREAK和.CONTINUE只能在伪指令.WHILE－.ENDW和.REPEAT－.UNTIL的循环体内使用。</p>
<p><strong>例6.12 显示9个数字字母’1’~’9’，26个大写字母，和显示任意输入的数字字符，并用按“回车”键来结束本程序的运行。</strong></p>
<p>解：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br></pre></td><td class="code"><pre><span class="line">DATA1 SEGMENT</span><br><span class="line"></span><br><span class="line">MSG1 DB　13, 10,?&quot;Iteration: &quot;</span><br><span class="line"></span><br><span class="line">NUM1 DB　&apos;1&apos;, &quot;$&quot;</span><br><span class="line"></span><br><span class="line">MSG2 DB　13, 10,?&quot;Alphabet: $&quot;</span><br><span class="line"></span><br><span class="line">NUM2 DB　&apos;A&apos;, &quot; $&quot;</span><br><span class="line"></span><br><span class="line">MSG3 DB　13, 10, &quot;Type digits, then press ENTER: $&quot;</span><br><span class="line"></span><br><span class="line">DATA1 ENDS</span><br><span class="line"></span><br><span class="line">CODE1 SEGMENT</span><br><span class="line"></span><br><span class="line">ASSUME　CS:CODE1, DS:DATA1</span><br><span class="line"></span><br><span class="line">START: MOV AX, DATA1</span><br><span class="line"></span><br><span class="line">MOV DS, AX</span><br><span class="line"></span><br><span class="line">MOV CX, 9</span><br><span class="line"></span><br><span class="line">MOV AH, 09H</span><br><span class="line"></span><br><span class="line">MOV DX, OFFSET MSG1</span><br><span class="line"></span><br><span class="line">.REPEAT</span><br><span class="line"></span><br><span class="line">INT　21H</span><br><span class="line"></span><br><span class="line">INC　NUM1 ;显示Iteration: 1,2,~,9</span><br><span class="line"></span><br><span class="line">.UNTILCXZ</span><br><span class="line"></span><br><span class="line">MOV DX, OFFSET MSG2</span><br><span class="line"></span><br><span class="line">INT 21H ;显示字符串&quot;Alphabet:&quot;</span><br><span class="line"></span><br><span class="line">MOV AH, 09H</span><br><span class="line"></span><br><span class="line">MOV DX, OFFSET NUM2</span><br><span class="line"></span><br><span class="line">.REPEAT</span><br><span class="line"></span><br><span class="line">INT　21H</span><br><span class="line"></span><br><span class="line">INC　NUM2 ;显示当前字母</span><br><span class="line"></span><br><span class="line">;当前字母向后移</span><br><span class="line"></span><br><span class="line">.UNTIL　NUM2 &gt; &apos;Z&apos; ;显示整个大写字母表</span><br><span class="line"></span><br><span class="line">MOV AH, 09H</span><br><span class="line"></span><br><span class="line">MOV DX, OFFSET MSG3</span><br><span class="line"></span><br><span class="line">INT 21H</span><br><span class="line"></span><br><span class="line">.WHILE?1 ;循环条件为永真的循环</span><br><span class="line"></span><br><span class="line">MOV　AH, 07H</span><br><span class="line"></span><br><span class="line">INT　21H ;不带回显地从键盘读一个字符</span><br><span class="line"></span><br><span class="line">.BREAK .IF AL == 13 ;如果输入“回车”键，则终止循环</span><br><span class="line"></span><br><span class="line">.CONTINUE .IF (AL&lt;&apos;0&apos;) || (AL&gt;&apos;9&apos;) ;如果字符不是数字字符，则继续循环</span><br><span class="line"></span><br><span class="line">MOV　DL, AL</span><br><span class="line"></span><br><span class="line">MOV　AH, 02H</span><br><span class="line"></span><br><span class="line">INT　21H ;显示所输入的数字字母</span><br><span class="line"></span><br><span class="line">.ENDW</span><br><span class="line"></span><br><span class="line">MOV AX, 4C00H</span><br><span class="line"></span><br><span class="line">INT 21H</span><br><span class="line"></span><br><span class="line">CODE1 ENDS</span><br><span class="line"></span><br><span class="line">END START</span><br></pre></td></tr></table></figure>
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/limh/tags/教程/" rel="tag"># 教程</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/limh/2015/04/01/asm23/" rel="next" title="6.1 源程序的基本组成">
                <i class="fa fa-chevron-left"></i> 6.1 源程序的基本组成
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/limh/2015/04/01/asm25/" rel="prev" title="6.3 段的基本属性">
                6.3 段的基本属性 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="SOHUCS"></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/limh/images/avatar.jpg" alt="土逗牛肉">
            
              <p class="site-author-name" itemprop="name">土逗牛肉</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/limh/archives/">
              
                  <span class="site-state-item-count">255</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/limh/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/limh/tags/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/limhGeek" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:1591054297@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/f73b243e7cc9" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-user-circle-o"></i>简书</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#6-2-1-顺序结构"><span class="nav-number">1.</span> <span class="nav-text">6.2.1 顺序结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-2-2-分支结构"><span class="nav-number">2.</span> <span class="nav-text">6.2.2 分支结构</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#一、显示转移指令实现的分支结构"><span class="nav-number">2.1.</span> <span class="nav-text">一、显示转移指令实现的分支结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#二、用伪指令实现的分支结构"><span class="nav-number">2.2.</span> <span class="nav-text">二、用伪指令实现的分支结构</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-2-3-循环结构"><span class="nav-number">3.</span> <span class="nav-text">6.2.3 循环结构</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#一、用循环指令构成循环结构"><span class="nav-number">3.1.</span> <span class="nav-text">一、用循环指令构成循环结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#二、用伪指令实现的循环结构"><span class="nav-number">3.2.</span> <span class="nav-text">二、用伪指令实现的循环结构</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1、WHILE型循环伪指令"><span class="nav-number">3.2.1.</span> <span class="nav-text">1、WHILE型循环伪指令</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2、REPEAT型循环伪指令"><span class="nav-number">3.2.2.</span> <span class="nav-text">2、REPEAT型循环伪指令</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3、辅助循环伪指令"><span class="nav-number">3.2.3.</span> <span class="nav-text">3、辅助循环伪指令</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-、终止循环伪指令"><span class="nav-number">3.2.3.1.</span> <span class="nav-text">(1)、终止循环伪指令</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-、循环继续伪指令"><span class="nav-number">3.2.3.2.</span> <span class="nav-text">(2)、循环继续伪指令</span></a></li></ol></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">土逗牛肉</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
	var str = GetUrlParam('height');
    if (str === '0'){
		document.getElementById('header').style.display = 'none';
		document.getElementById('comments').style.display = 'none';
		document.getElementById('footer').style.display = 'none';
		document.getElementsByClassName('post-footer').item(0).style.display = 'none'
	}
	
    function GetUrlParam(paraName) {
        var url = document.location.toString();
        var arrObj = url.split("?");

        if (arrObj.length > 1) {
            var arrPara = arrObj[1].split("&");
            var arr;

            for (var i = 0; i < arrPara.length; i++) {
                 arr = arrPara[i].split("=");

                if (arr != null && arr[0] === paraName) {
                    return arr[1];
                }
            }
            return "";
        } else {
            return "";
        }
    }
</script>









  












  
  
    <script type="text/javascript" src="/limh/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/limh/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/limh/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/limh/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/limh/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/limh/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/limh/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/limh/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
